﻿@{
    ViewBag.Title = "发起项目";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model LY.Entity.R_ProjectItem

<link href="~/Content/validform.css" rel="stylesheet" />
<script src="~/Scripts/Validform_v5.3.2_min.js"></script>
<script src="~/Scripts/Validform_Datatype.js"></script>

<script src="~/Content/assets/app/common/ajaxupload.js"></script>
<script src="~/Content/assets/plugins/xjgrid/xjgrid.js"></script>

<script type="text/javascript">
    var util = {};
    var options = {
        listUrl: "@Url.Action("ProjectItem", new { projectid = Model.ProjectId })",
        uploadUrl: "@Url.Action("UploadImg", "Helper")",

    };
    var gridopt = {
        url: options.listUrl,
        colModel: [
            { display: '序号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
            { display: '回报内容', name: 'MRedoundContent', width: "60%", sortable: false  },  
             { display: '名额', name: 'Limits', width: "10%", sortable: false, align: 'center' },
            { display: '支持金额(元)', name: 'Amount', width: "10%", sortable: true, align: 'center' },
            { display: '运费', name: 'Freight', width: "10%", sortable: false, align: 'center' },
            { display: '操作', name: 'Id', width: "10%", sortable: false, align: 'center', process: processOp }
        ],
        sortname: "Id",
        sortorder: "DESC",
        title: false,
        rp: 5,
        usepager: true,
        showcheckbox: false
    };
    $(function () {

        $("form").Validform({
            tiptype: 3
        });
        //图片初始化
        init();
        var sign = $("#sign").val(); 
        if (sign == 1) {
            add();
        } else {
            cancel();
        }
 

        $('#add').click(function () {
            add();
        });
        //点击取消
        $('#cancel').click(function () {
            //刷新页面
            window.location.href = "/Project/AddProjectItem?proid=" + $("#ProjectId").val();
            //cancel();
        });

        //点击上一步
        $("#back").click(function () {
            window.location.href = "/Project/AddProject" + "/" + $("#ProjectId").val();
        });
        var xjgrid = new xjGrid("gridlist", gridopt);
    });

    function OnSuccess(data) {
        if (data.Status == 1) {
            $.dialog.tips(data.Message, 1, 'tips.gif', function () {
                //cancel();
                //new xjGrid("gridlist", gridopt);
                window.location.href = data.Data;
            });
        } else {
            $.dialog.tips(data.Message);
            return false;
        }
        return false;

    }

    function begin() {
        var fileName = document.getElementById("fileName").value;
        if (fileName == "") {
            alert("请上传回报图片！");
            return false;
        }
    }

    //添加方法
    function add() {
        $("#additem1").css('display', '');
        $("#add").css('display', 'none');
        $("#preview").css('display', 'none');
        $("#sure").css('display', '');
        $("#cancel").css('display', '');
    }
    //取消方法
    function cancel() {

        //var url = options.editUrl;
        //location.href = url;
        $("#additem1").css('display', 'none');
        $("#add").css('display', '');
        $("#preview").css('display', '');
        $("#sure").css('display', 'none');
        $("#cancel").css('display', 'none');
    }

    function processOp(value, cell) {
        var ops = [];
        ops.push("&nbsp;<a title='编辑' href='javascript:;'  class='b-l-btn' onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
        ops.push("&nbsp;&nbsp;<a title='删除' class='b-l-btn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
        return ops.join("");
    }
    // var proid = $("#ProjectId").val();
    //编辑
    util.Edit = function (id) {
        var url = "/Project/AddProjectItem/" + id + "?proid="+@Model.ProjectId;
        // var url = "/Project/ProjectItemSave";
        location.href = url;
    };
    //删除
    util.Delete = function (id, name) {
        $.dialog.confirm('您确定要删除此条回报吗？', function () {
            $.post("/Project/DeleteProjectItem" + "/" + id, { id: id },
                function (res) {
                    if (res.Status > 0) {
                        $.dialog.tips(res.Message, 1, 'tips.gif', function () {
                            window.location.href = "/Project/AddProjectItem?proid=" + $("#ProjectId").val();
                        });
                    }
                    else {
                        $.dialog.alert(res.Message);
                    }
                },
                "json"
            );
        });
    };

    var g_AjxTempDir = "/FileUpload/";
    //初始化  
    function init() {
        //初始化图片上传  
        var btnImg = document.getElementById("btnUploadImg");
        var img = document.getElementById("imgShow");

        var TitlePic = "111";
        var Pictures = "111";
        var fileName = document.getElementById("fileName");

        g_AjxUploadImg(btnImg, img, TitlePic, Pictures, fileName);
    }

    function g_AjxUploadImg(btn, img, TitlePic, Pictures, fileName) {
        var button = btn, interval;
        new AjaxUpload(button, {
            action: options.uploadUrl,
            data: {},
            name: 'myfile',
            onSubmit: function (file, ext) {
                if (!(ext && /^(jpg|JPG|png|PNG|gif|GIF)$/.test(ext))) {
                    alert("您上传的图片格式不对，请重新选择！");
                    return false;
                }
            },
            onComplete: function (file, response) {
                flagValue = response;
                if (flagValue == "-1") {
                    alert("您上传的图片格式不对，请重新选择！");
                } else if (flagValue == "-2") {
                    alert("您上传的图片大于200K，请重新选择！");
                } else if (flagValue == "-3") {

                    alert("图片上传失败！");
                } else {

                    //$.dialog.tips(res.Message, 1, 'tips.gif', function () {
                    //    xjgrid.Reload();
                    //});


                    var strs = new Array();
                    strs = response.split("/");

                    var Pictures2 = "";
                    var fileName2 = "";
                    for (var i = 0; i < strs.length; i++) {
                        if (i == 0) {
                            TitlePic.value = strs[i];
                        } else if (i == 1) {
                            Pictures.value = strs[i];
                            Pictures2 = strs[i];

                        } else if (i == 2) {
                            fileName2 = strs[i];
                        }
                    }
                    img.src = g_AjxTempDir + fileName2 + "/" + Pictures2;
                    fileName.value = g_AjxTempDir + fileName2 + "/" + Pictures2;
                }
            }
        });
    }

</script>
<style>
    #btnUploadImg {
        text-align: center;
        line-height: 20px;
        height: 20px;
        margin: 0px;
        padding: 0px;
        border: 0px;
        float: left;
        width: 130px;
        height: 25px;
        font-size: 10pt;
    }

    em {
        float: left;
        margin: 0px 10px;
    }
</style>

<div class="line10"></div>

<div class="container">
    <div class="order-process">
        <ul>
            <li class="active">项目及发起人信息</li>
            <li class="active">回报设置</li>
            <li>确认信息</li>
            <li>完成</li>
        </ul>
    </div>
    <div class="center">
        <h2>回报设置</h2>
        <div id="hideGrid">
            <div id="gridlist">
            </div>
        </div>
    </div>
    @using (Ajax.BeginForm("ProjectItemSave", new AjaxOptions() { OnSuccess = "OnSuccess", OnBegin = "begin" }))
    {  
        @Html.HiddenFor(model => model.Id)
        @Html.HiddenFor(model => model.ProjectId)
        @Html.HiddenFor(model => model.Createtime) 
     
@*<input type="hidden" id="Id" name="Id" value="@Model.Id" />*@
        <div class="additem" id="additem1" style="display: none;">
            <h4 id="editInfo">添加回报选项</h4>
            <dl>
                <dt>回报类别：</dt>
                <dd>
                    @Html.ResourceRadioList("RedoundType", "RedoundType", Model.RedoundType == null ? 0 : Model.RedoundType, true)
                </dd>
            </dl>

            <dl>
                <dt><span style="color: red">*</span>支持金额：</dt>
                <dd>
                    <input type="text" class="input txt" placeholder="不少于0元" name="Amount" id="Amount" value="@Model.Amount" datatype="num" >
                    元
                </dd>
            </dl>
            <dl style="margin-top: 8px">
                <dt><span style="color: red">*</span>回报简介：</dt>
                <dd>
                    <textarea id="RedoundContent" name="RedoundContent" class="input normal1" datatype="*" placeholder="最多不超过200个字" style="height: 50px" maxlength="200">@Model.RedoundContent</textarea>
                </dd>
            </dl>
            <dl style="margin-top: 3px">
                <dt><span style="color: red">*</span>回报内容：</dt>
                <dd>
                    <textarea id="MRedoundContent" name="MRedoundContent" maxlength="1000" datatype="*" placeholder="最多不超过1000个字" class="input normal1">@Model.MRedoundContent</textarea>
                </dd>
            </dl>
            <dl>
                <dt><span style="color: red">*</span>回报展示图片：</dt>
                <dd>
                    <div class="uploadImg">
                        <input type="button" id="btnUploadImg" value="上传首屏图片" class="button" /><em>支持jpg、jpeg、png、gif格式，大小：325 X 250px</em>
                    </div>
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd>
                    <img id="imgShow" style="width: 296px; height: 180px" src="@Model.RedoundImage"/>
                    <input type="hidden" id="fileName" name="RedoundImage"  value="@Model.RedoundImage" />
                </dd>
            </dl>
            <dl>
                <dt>限定名额：</dt>
                <dd>
                    <input type="text" class="input normal" placeholder="0" id="Limits" name="Limits" value="@Model.Limits" style="float: left;width: 100px">
                    <em>“0”为不限名额</em>
                </dd>
            </dl>
            <dl>
                <dt>运费：</dt>
                <dd>
                    <input type="text" class="input normal" placeholder="0" id="Freight" name="Freight" value="@Model.Freight" style="float: left;width: 100px">
                    <em>元</em><em>“0”为包邮</em>
                </dd>
            </dl>
            <dl>
                <dt>回报时间：</dt>
                <dd>项目结束后
                    <input type="text" class="input txt" id="DedoundDays" name="DedoundDays" datatype="num" value="@Model.DedoundDays" style="width: 100px">
                    天，将会向支持者发送回报
                </dd>
            </dl>
            <dl>
                <dt></dt>
                <dd>
                    <input type="hidden" id="sign" value="@ViewBag.sign"/>
                </dd>
            </dl>
        </div>
        <div class="btn-list">
            <a id="add" class="button">添加回报</a>
            <a href="@Url.Action("Detail", "Default", new { id = Model.ProjectId })" id="preview" target="_blank" class="button">预览</a>
            <input type="submit" id="sure" style="display: none;" class="button" value="确定" />
            <a id="cancel" style="display: none;" class="button">取消</a>
        </div>
    }
    <hr />
    <div class="btn-list">
        <div class="listTips" style="margin: 10px 100px; padding-left: 30px;">
            <b>温馨提示：</b>
            <p>
                您可以设置多个回报，多些选择能提高项目的支持率；多个回报建议为不同档次的回报，能让你的项目更快成功。<br />
                回报内容最好是项目的衍生品，与项目内容有关的回报更能吸引到大家的支持。
            </p>
        </div>
        <div class="line30"></div>
        <a id="back" class="button">上一步</a>
        <a id="next" href="../Project/ConfirmProject?proid=@Model.ProjectId" class="button">下一步</a>

    </div>
    <div class="line30"></div>
</div>
